home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 October / Macworld (1998-10).dmg / Shareware World / Info / For Developers / MacZoop 1.8.4 / More Classes / Window Classes / ZScroller.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-05  |  4.2 KB  |  160 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            ZScroller.h            -- a window with scrollbars
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZSCROLLER__
  25. #define    __ZSCROLLER__
  26.  
  27. #include    "ZWindow.h"
  28.  
  29. /*
  30.  ZScroller is a window that has scrollbars in the usual way. The scrollBounds sets the size
  31.  of the area that the window can show- if this is ever less than the window content the
  32.  scrollbars will be disabled. The scale values set how many pixels to move in each direction
  33.  for each increment of the scrollbar. Override this class to implement scrolling windows with
  34.  REAL content.
  35. */
  36.  
  37.  
  38. // set up streaming stuff:
  39.  
  40. DEFINECLASSID( ZScroller, 'zscr' );
  41.  
  42. // class def:
  43.  
  44. class    ZScroller : public ZWindow
  45. {
  46. protected:
  47.     ControlHandle        theHBar;        // handle to horizontal scrollbar
  48.     ControlHandle        theVBar;        // handle to vertical scrollbar
  49.     Rect                bounds;            // scrollable area (virtual document size)
  50.     short                hScale;            // pixels shifted per unit horizontally
  51.     short                vScale;            // pixels shifted per until vertically
  52.     Boolean                hasHBar;        // true if has horizontal bar
  53.     Boolean                hasVBar;        // true if has vertical bar
  54.     short                cInitValue;        // used for live scrolling support
  55.  
  56. public:
  57.     
  58.     ZScroller(    ZCommander* aBoss,
  59.                 const short windID,
  60.                 const Boolean hasHScroll = TRUE,
  61.                 const Boolean hasVScroll = TRUE );
  62.                 
  63.     ZScroller();
  64.     
  65. // ZWindow overrides:
  66.     virtual void    InitZWindow();
  67.     virtual void    Activate();
  68.     virtual void    Deactivate();
  69.     virtual void    Draw();
  70.     virtual void    DrawGrow();
  71.     virtual void    Click( const Point mouse, const short modifiers );
  72.     virtual void    SetSize( const short width, const short height, const Boolean reDraw = TRUE);
  73.     virtual void    Zoom( const short partCode );
  74.     virtual void    SetBounds( const Rect& aBounds );
  75.     virtual void    SetBounds( short top, short left, short bottom, short right );
  76.     virtual void    SetBounds( Point tl, Point br );
  77.     virtual void    GetBounds( Rect* aBounds );
  78.     virtual void    GetIdealWindowZoomSize( Rect* idealSize );
  79.  
  80.     virtual void    GetContentRect( Rect* aRect );
  81.     virtual void    ClickContent( const Point mouse, const short modifiers ) {};
  82.     
  83. // ZScroller methods:    
  84.     virtual void    SetScrollAmount( const short hAmount, const short vAmount );
  85.     virtual void    GetPosition( short* hPosition, short* vPosition );
  86.     virtual void    ScrollTo( const short hPosition, const short vPosition );
  87.     virtual void    Scroll( const short dH, const short dV );
  88.     
  89.     virtual Boolean    AutoScroll( Point mousePt );
  90.     
  91. // streaming:
  92.  
  93.     virtual void    WriteToStream( ZStream* aStream );
  94.     virtual void    ReadFromStream( ZStream* aStream );
  95.  
  96. protected:
  97.  
  98.     virtual void    CalculateControlParams();
  99.     virtual void    MakeScrollbars();
  100.     virtual void    MoveScrollbars();
  101.     virtual void    PostScroll( ControlHandle aCtl = NULL );
  102.     virtual void    SetOriginToScroll();
  103.     virtual void    HideScrollbars( Boolean validateArea = FALSE );
  104.  
  105. public:
  106.  
  107.     virtual void    ScrollHandler( const ControlHandle aCtl, const short partCode );
  108. };
  109.  
  110.  
  111.  
  112. // compiler flags:
  113.  
  114. // ZScroller by default sets up a thumb action procedure to implement "live scrolling". If you'd
  115. // prefer to use the more traditional non-live scrolling, undefine the following conditional.
  116.  
  117. #define    _LIVE_SCROLLING        1
  118.  
  119. // for live scrolling we require a UPP definition for the thumb proc- Apple's interfaces
  120. // omit this, so we do that here
  121.  
  122. #ifdef _LIVE_SCROLLING
  123.  
  124. #define            kWidthOfScrollArrow        24
  125.  
  126. // UPP:
  127.  
  128. typedef pascal void    (*ThumbActionProcPtr)();
  129.  
  130. #if GENERATINGCFM
  131. typedef UniversalProcPtr ThumbActionUPP;
  132. #else
  133. typedef ThumbActionProcPtr ThumbActionUPP;
  134. #endif
  135.  
  136. enum
  137. {
  138.     uppThumbActionProcInfo = kPascalStackBased
  139. };
  140.  
  141. #if GENERATINGCFM
  142. #define NewThumbActionProc(userRoutine)        \
  143.         (ThumbActionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThumbActionProcInfo, GetCurrentArchitecture())
  144. #else
  145. #define NewThumbActionProc(userRoutine)        \
  146.         ((ThumbActionUPP) (userRoutine))
  147. #endif
  148.  
  149. #if GENERATINGCFM
  150. #define CallThumbActionProc(userRoutine)        \
  151.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppThumbActionProcInfo )
  152. #else
  153. #define CallThumbActionProc(userRoutine )        \
  154.         (*(userRoutine))()
  155. #endif
  156.  
  157.  
  158. #endif
  159.  
  160. #endif